﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Graphe.Collations;

namespace Graphe.Windows.Controls.Collations
{
    public class SacrumControl : StackPanel, ICollationControl
    {
        public SacrumControl()
        {
            Loaded += new RoutedEventHandler(SacrumControl_Loaded);
        }

        private ManuscriptListControl _manuscriptListControl;
        private CollationTextBlock _textBlockText;

        #region Public Properties

        public Sacrum Sacrum { get; set; }

        #endregion
        #region ICollationControl Members

        public bool Selected
        {
            set
            {
                _textBlockText.Selected = value;
            }
        }

        #endregion


        private void SacrumControl_Loaded(object sender, RoutedEventArgs e)
        {
            Style = CollationsControlStylePicker.FindProperVersionResource("ManuscriptsControlPanelStyle") as Style;

            MouseDown += new System.Windows.Input.MouseButtonEventHandler(SacrumControl_MouseDown);
        }

        void SacrumControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            CollationControlController.Instance.SelectedICollationControl = this;
            e.Handled = true;
        }



        public void Render()
        {
            Children.Clear();
            Style = CollationsControlStylePicker.FindProperVersionResource("SacrumControlStyle") as Style;

            _textBlockText = new CollationTextBlock();
            _textBlockText.Text = Sacrum.Text + " = " + Sacrum.Representation;
            _textBlockText.Style = CollationsControlStylePicker.FindProperVersionResource("SacrumTextStyle") as Style;
            _textBlockText.Tag = Sacrum;
            Children.Add(_textBlockText);

            _manuscriptListControl = new ManuscriptListControl();
            _manuscriptListControl.Manuscripts = Sacrum.Manuscripts;
            _manuscriptListControl.Render();
            Children.Add(_manuscriptListControl);
        }
    }
}
